package com.example.domain.dto.pricing;

import com.example.domain.dto.MoneyDTO;
import com.example.domain.entity.ThresholdDiscountRule;
import com.example.domain.valueobject.Money;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 满减折扣规则DTO
 * 
 * @author Means
 * @since 2025-10-27
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ThresholdDiscountRuleDTO {
    
    /**
     * 规则ID
     */
    private String id;
    
    /**
     * 优惠规则ID
     */
    private String pricingRuleId;
    
    /**
     * 最低消费金额
     */
    private MoneyDTO thresholdAmount;
    
    /**
     * 减免金额（如满100减20）
     */
    private MoneyDTO discountAmount;
    
    /**
     * 是否可叠加
     */
    private Boolean stackable;
    
    /**
     * 满减门槛是否使用原价判断
     */
    private Boolean thresholdUseOriginalPrice;
    
    /**
     * 优先级（用于排序）
     */
    private Integer priority;
    
    /**
     * 从实体类创建DTO
     * 
     * @param rule 满减折扣规则实体
     * @return ThresholdDiscountRuleDTO
     */
    public static ThresholdDiscountRuleDTO from(ThresholdDiscountRule rule) {
        if (rule == null) {
            return null;
        }
        
        return ThresholdDiscountRuleDTO.builder()
                .id(rule.getId())
                .pricingRuleId(rule.getRuleId())
                .thresholdAmount(rule.getThresholdAmount() != null ? MoneyDTO.from(Money.of(rule.getThresholdAmount())) : null)
                .discountAmount(rule.getDiscountAmount() != null ? MoneyDTO.from(Money.of(rule.getDiscountAmount())) : null)
                .stackable(rule.getStackable())
                .thresholdUseOriginalPrice(rule.getThresholdUseOriginalPrice())
                .build();
    }
}

